package mortal.game.manager
{
	import com.gengine.global.*;
	import flash.display.*;
	import mortal.mvc.core.*;
	import mortal.mvc.interfaces.*;
	
	public class UILayer extends View implements ILayer
	{
		
		public function UILayer()
		{
			tabChildren = false;
			mouseEnabled = false;
		}
		
		public function addPopUp(obj:DisplayObject, bol:Boolean = false) : void
		{
			if (obj && this.contains(obj) == false)
			{
				this.addChild(obj);
			}
		}
		
		public function centerPopup(obj:DisplayObject) : void
		{
			obj.x = (Global.stage.stageWidth - obj.width) / 2;
			obj.y = (Global.stage.stageHeight - obj.height) / 2;
		}
		
		public function setPosition(obj:DisplayObject, X:int, Y:int) : void
		{
			obj.x = X;
			obj.y = Y;
		}
		
		public function isTop(obj:DisplayObject) : Boolean
		{
			if (this.contains(obj))
			{
				return this.getChildIndex(obj) == (this.numChildren - 1);
			}
			return false;
		}
		
		public function removePopup(obj:DisplayObject) : void
		{
			if (this.contains(obj))
			{
				this.removeChild(obj);
			}
		}
		
		public function isPopup(obj:DisplayObject) : Boolean
		{
			return this.contains(obj);
		}
		
		public function setTop(obj:DisplayObject) : void
		{
			if (this.contains(obj))
			{
				if (this.getChildIndex(obj) != (this.numChildren - 1))
				{
					this.setChildIndex(obj, (this.numChildren - 1));
				}
			}
		}
		
		public function resize(scaleX:Number, scaleY:Number) : void
		{
			var childObj:DisplayObject = null;
			var i:int = 0;
			while (i < numChildren)
			{
				
				childObj = this.getChildAt(i);
				childObj.x = childObj.x * scaleX;
				childObj.y = childObj.y * scaleY;
				i++;
			}
		}
	}
}
